<?
 class Story
 {
  
    var $db;
	var $tbl_story;
 
    function Story($db,$tbl_story)
    {
        $this->db = $db;
	    $this->tbl_story = $tbl_story;
    }
    
    function InsertStory($post)
    {
	   $post['date'] = time();
	   $exept_arr = array("action","answer");
	   $q = $this->db->MakeQuery($post,$exept_arr); 
       $query = "INSERT INTO $this->tbl_story SET ".$q;
       $this->db->RunQuery($query);
    }
    
    function UpdateStory($date,$text,$id)
    {
       $query = "UPDATE $this->tbl_story SET date='".$date."', text='".$text."' WHERE id='".$id."'";
       mysql_query($query) or die (mysql_error());
    }
    
    function SelectStory()
    {
       $query="SELECT * FROM $this->tbl_story ORDER BY date DESC";
       $arr=$this->db->ArrFromQuery($query);
       return $arr;
    }

    function SelectOneStory($id)
    {
       $query = "SELECT * FROM $this->tbl_story WHERE id='".$id."'";
       $onenews = $this->db->ArrFromQuery($query);
       return $onenews;
    }
    
    function DeleteStory($id)
    {
       $query = "DELETE FROM $this->tbl_story WHERE id='".$id."'";
       $this->db->RunQuery($query);
    }
 }
?>
